<template>
    <div>
        <el-card class="box-card" shadow="hover">
            <div slot="header" class="clearfix">
              <span>抽取评审专家（系统需要到了“开标时间”过后，专家才能对当前招标文件进行评审）</span>
              <div style="float: right;">
                <el-button size="small" @click="onClose">取消</el-button>
                <el-button size="small" type="primary" @click="submitChoice">提交</el-button>
            </div>
            </div>
            <table class="custom-table">
                <tr>
                    <td class="tr-title">专家</td><td>
                      <el-select v-model="expertIds" multiple placeholder="请选择">
                        <el-option
                          v-for="item in options"
                          :key="item.id"
                          :label="item.name"
                          :value="item.id">
                        </el-option>
                      </el-select>
                    </td>
                    <td class="tr-title">开标时间</td><td>
                        <el-date-picker
                            v-model="openTime"
                            type="datetime"
                            placeholder="选择日期时间"
                            align="right">
                        </el-date-picker>
                    </td>
                </tr>
            </table>
        </el-card>
    </div>
</template>

<script>
   
import moment from 'moment'
import store from '@/store'
import { bidPurchaseRoleIdUserSave } from "@/api/labour_purchase_api"
export default {
    props: ['row'],
    data() {
        return {
            expertIds:'',//处理人id
            options:[],//专家数据
            openTime:''//开标时间
        };
    },
    filters: {
        formatData(value) {
            if (!value) {
                return ''
            }
            return moment(value).format("YYYY-MM-DD")
        },
        formatTime(value) {
            if (!value) {
                return ''
            }
            return moment(value).format("YYYY-MM-DD HH:mm:ss")
        }
    },
    created(){
        this.roleIdGetUser();
    },
    methods: {
        async roleIdGetUser(){
            this.options = await store.dispatch('user/roleIdGetUserSelect',35);//35是指定的专家角色
        },
        submitChoice(){
            if(!this.expertIds && this.expertIds.length === 0){
                return this.$message.error('请选择专家');
            }
            if(!this.openTime){
                return this.$message.error('请选择开标时间，且开标时间不能小于报名结束时间');
            }
            
            this.$confirm('确认提交？', "提示", {
                    confirmButtonText: "确定",
                    cancelButtonText: "取消",
                    type: "warning"
            }).then(async () => {
                const params = {
                    expertIds:this.expertIds.join(','),
                    openTime:this.openTime,
                    id:this.row.id
                }
                const {code} = await bidPurchaseRoleIdUserSave(params);
                if(code === 200){
                    this.$message.success('分配成功！');
                    this.onClose();
                }
            }).catch((error) => {});
           
        },
        onClose() {
            this.expertIds = '';
            this.openTime = '';
            this.options = [];
            this.$emit("on-cancel-click","choiceReview");
        }
    }
};
</script>
    
    